import Author from '@/components/Author'
import { getPrizeSecondCheckList } from '@/api/prize'
import { getFaculty } from '@/api/account'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { statusFilter } from '@/utils/variable'
// 权限判断指令
import permission from '@/directive/permission/index.js'
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'

const defaultListQuery = {
  page: 1,
  limit: 10,
  ordering: '-id',
  title: '',
  faculty_code:'view_all_second_faculty'
}

export default {
  // name: 'FirstCheckBookList',
  components: { Pagination, Author, ElImageViewer },
  directives: { permission },
  filters: {
    statusFilter
  },
  data() {
    return {
      tableKey: 0,
      list: [],
      facultyList:[],
      total: 0,
      listLoading: true,
      // 查询条件
      listQuery: Object.assign({}, defaultListQuery)
    }
  },
  // activated() {
  //   const refresh = this.$route.params.refresh
  //   if (refresh) {
  //     this.init()
  //   }
  // },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.getList()
      this.getFaculty()
    },

    // 获取表格数据
    getList() {
      let list=['view_all_second_faculty','10100','10200','10300','10400','10500','10600','10700','10800','10900','11000','11100','11200','11300','11400','11500','11600','11700','11800','20100','20200','20300','20400','20500','20600','20700','20800','20900','21000','21100']
      let roles=JSON.parse(JSON.stringify(this.$store.state.user.roles))
      for (let i = 0; i < list.length; i++) {
        if(roles.indexOf(list[i])>-1){
          this.listQuery.faculty_code=list[i]
          break
        }
      }
      this.listLoading = true
      getPrizeSecondCheckList(this.listQuery).then(response => {
        this.list = response.results
        this.total = response.count

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 0.5 * 1000)
      })
    },

    getFaculty(){
      getFaculty().then(res=>{
        this.facultyList=res
      })
    },
    // 搜索事件
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    // 重置搜索条件
    resetFilter() {
      this.listQuery = Object.assign({}, defaultListQuery)
    },

    // 点击审核
    handleCheck(row) {
      this.$router.push({
        name: 'PrizeSecondCheck',
        query: { from: 'SecondCheckPrizeList', id: row.id }
      })
    }

  }
}
